#−∗− coding: utf−8−∗−
#Autor: Vitor Letras n.º 3947

import numpy as np
import matplotlib.pyplot as plt

import os

GRAPHDIR = 'graph/'

"""
Este modulo cria os graficos resultantes das listas que recebe.
"""

def autolabel(rects, ax):
    for rect in rects:
        h = rect.get_height()
        ax.text(rect.get_x()+rect.get_width()/2., 1.05*h, h,
                ha='center', va='bottom')

def plotGraph(values, ylabel, filename):
    N = len(values)
    ind = np.arange(N)  # the x locations for the groups
    width = 0.27       # the width of the bars

    fig = plt.figure()
    ax = fig.add_subplot(111)

    yvals = [value for description, value in values]
    rects1 = ax.bar(ind, yvals, width, color='r')

    ax.set_ylabel(ylabel)
    ax.set_xticks(ind + (width / 2))
    ax.set_xticklabels([description.decode('utf-8') for description, values in values], rotation = 'vertical')

    autolabel(rects1, ax)
    plt.show()
    if not os.path.exists(GRAPHDIR):
	    os.makedirs(GRAPHDIR)
    fig.savefig(GRAPHDIR + filename, dpi=300)
